package cn.njyd.corejava.thread.myday02;

public class JoinMethodTest02 {
    public static void main(String[] args) {
        Thread redLight = new Thread(()->{
            for (int i=0;i<5;i++) {
                System.out.println("红灯-"+(5-i)+"-");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread yellowLight = new Thread(()->{
            try {
                redLight.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i=0;i<5;i++) {
                System.out.println("黄灯-"+(5-i)+"-");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread greenLight = new Thread(()->{
            try {
                yellowLight.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i=0;i<5;i++) {
                System.out.println("绿灯-"+(5-i)+"-");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        redLight.start();
        yellowLight.start();
        greenLight.start();
    }
}
